﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fast.Framework.Extensions
{

    /// <summary>
    /// 字典扩展类
    /// </summary>
    public static class DictionaryExtensions
    {

        /// <summary>
        /// 追加
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">源</param>
        /// <param name="element">元素</param>
        public static void Append<T>(this Dictionary<string, object> source, Dictionary<string, T> element)
        {
            foreach (var item in element)
            {
                source.Add(item.Key, item.Value);
            }
        }

        /// <summary>
        /// 添加自增键
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">源</param>
        /// <param name="values">值</param>
        /// <param name="startIndex">开始索引</param>
        public static Dictionary<string, T> AddIdentityKey<T>(this Dictionary<string, T> source, List<T> values, int startIndex)
        {
            var name = typeof(T).Name.ToLower();
            foreach (var value in values)
            {
                source.Add($"{name}_{startIndex}", value);
                startIndex++;
            }
            return source;
        }
    }
}
